package com.example.braden.answergame.common.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.braden.answergame.R;
import com.example.braden.answergame.common.ImageLoader;
import com.example.braden.answergame.modules.main.domain.UserPropInfo;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by braden on 2018/3/2.
 * 道具view
 */

public class PropView extends RelativeLayout {
    @BindView(R.id.iv_prop_icon) ImageView ivPropIcon;
    @BindView(R.id.tv_prop_nums) TextView tvPropNums;
    @BindView(R.id.rl_prop_num_bg) LinearLayout rlPropNumBg;
    @BindView(R.id.iv_gold_icon) ImageView ivGoldIcon;
    private Context mContext;

    public PropView(Context context) {
        super(context);
        this.mContext = context;
        initView();
    }

    public PropView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        initView();
    }

    private void initView() {
        LayoutInflater.from(mContext).inflate(R.layout.prop_layout, this);
        ButterKnife.bind(this);
    }

    public void setNumVisible() {
        rlPropNumBg.setVisibility(VISIBLE);
    }

    /**
     * 显示道具的个数
     */
    public void showPropNums(int propNums) {
        rlPropNumBg.setBackgroundResource(R.drawable.prop_nums_shape);
        tvPropNums.setTextColor(Color.WHITE);
        ivGoldIcon.setVisibility(GONE);
        tvPropNums.setText(propNums + "");
    }

    /**
     * 设置道具View
     */
    public void setPropView(UserPropInfo.BodyBean.PropsBean prop) {
        ImageLoader.load(mContext, prop.getIcon(), R.mipmap.gold_icon, ivPropIcon);
        if (prop.getCount() > 0) {
            showPropNums(prop.getCount());
        } else {
            showGoldNums(prop.getPrice());
        }
    }

    /**
     * 道具个数为0，显示道具价格
     */
    public void showGoldNums(int price) {
        ivGoldIcon.setVisibility(VISIBLE);
        rlPropNumBg.setBackgroundResource(R.drawable.prop_price_shape);
        tvPropNums.setTextColor(mContext.getResources().getColor(R.color.prop_bg_outer));
        tvPropNums.setText(price + "");
    }
}
